package 计数法.找到所有数组中消失的数字;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * TODO
 *
 * @className: zdsyszzxsdsz
 * @description: TODO
 * @author: 等什么柠檬君
 * @date: 2022-05-04 18:27
 **/
public class zdsyszzxsdsz {
    public static void main(String[] args) {
        int[] a1 = {4,3,2,7,8,2,3,1};
        System.out.println(findDisappearedNumbers(a1));

//        List<Integer> arr = new ArrayList();
//        List<Integer> arr2 = new ArrayList();
//        for (int i = 1; i <= a1.length; i++) {
//            arr.add(i-1, i);
//            arr2.add(i-1,a1[i-1]);
//        }
//        System.out.println(arr);
//        System.out.println(arr2);
//        System.out.println(arr.removeAll(arr2));
//        System.out.println(arr);

    }
    public static List<Integer> findDisappearedNumbers(int[] nums) {
        Arrays.sort(nums);
        System.out.println(Arrays.toString(nums));
        ArrayList result = new ArrayList();


        for (int i = 1; i <= nums.length; ++i) {
            final int binary = binary(nums, i);
            if (binary!=-1){
                result.add(binary);
            }

//            result.add(nums[temp]);
        }
        return result;
    }

    public static int binary(int[] nums, int target){
        int right = nums.length-1;
        int left = 0;
        int mid = (right+left) >> 2;
        while (left <= right){
            if (target < nums[mid]){
                right = mid - 1;
            }
            if (target > nums[mid]){
                left = mid + 1;
            }
            if (target == nums[mid]){
                return -1;
            }
            mid = (left+right) >> 1;

        }
        System.out.println("target "+target);
        return target;
    }
}
